/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package db;

/**
 *
 * @author aluno
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class ConnectionFactory {
/*
    private static final String URL="jdbc:postgresql://localhost:5432/Flex";
    private static final String DRIVER="org.postgresql.Driver";
    private static final String USUARIO="postgres";
    private static final String SENHA="123";

  
    public static Connection getConnection() throws SQLException {
      try {
           Class.forName(DRIVER);
           return DriverManager.getConnection(URL, USUARIO, SENHA);
      }  catch (ClassNotFoundException e)  {
          throw new SQLException(e.getMessage());
      }
    }

     public static Connection getConnection(boolean pool) throws SQLException, NamingException {
                 Context ctx = new InitialContext();
                     DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/postgresql");
                    return ds.getConnection();
    }
    * 
    */
 public static Connection getConnection(
            String url,
            String usuario,
            String senha ) throws SQLException {
        // retorna a conexão a partir do método getConnection de DriverManager
        return DriverManager.getConnection( url, usuario, senha );
    }

 




}
